package com.netbetter.langzheng.client.mvc;

import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.netbetter.langzheng.commons.constants.AppEvents;

/**
 * 应用入口
 * 
 * @author 嘉陵江里捉鱼
 * 
 */
public class AppController extends Controller {

  private AppView appView;

  public AppController() {
    registerEventTypes(AppEvents.Init);
    registerEventTypes(AppEvents.Login);
    registerEventTypes(AppEvents.Error);
  }

  public void handleEvent(AppEvent event) {
    switch (event.type) {
      case AppEvents.Init:
        onInit(event);
        break;
      case AppEvents.Login:
        onLogin(event);
        break;
      case AppEvents.Error:
        onError(event);
        break;
    }
  }

  public void initialize() {
    appView = new AppView(this);
  }

  protected void onError(AppEvent ae) {
    System.out.println("error");
  }

  private void onInit(AppEvent event) {
    forwardToView(appView, event);

  }

  private void onLogin(AppEvent event) {
    forwardToView(appView, event);
  }

}
